/*
 * @(#)RunnableCalculator.java    Jul 19, 2010
 *
 * Copyright 2009 Nyber Shanghai, Inc. All rights reserved.
 */

package com.lab.util.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * Class description goes here.
 *
 * @author nickevin@gmail.com
 * @version Jul 19, 2010 9:28:15 AM
 */

public class RunnableCalculator implements Runnable {

	private SingleThreadCalculator calc;
	private long[] values;
	private int start;
	private int end;
	private long result;

	private CountDownLatch doneSignal;

	public RunnableCalculator(SingleThreadCalculator calc, long[] values,
			int start, int end, CountDownLatch doneSignal) {
		this.calc = calc;
		this.values = values; // for fast performance, no copy  
		this.start = start;
		this.end = end;
		this.doneSignal = doneSignal;
	}

	public void run() {
		System.out.println("Thread: " + Thread.currentThread() + " start="
				+ start + " end=" + end);
		result = calc.calc(values, start, end);
		doneSignal.countDown();
	}

	public long getResult() {
		return result;
	}
}
